home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / swingall.jar / javax / swing / text / AbstractDocument$AbstractElement.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-07-15  |  7.2 KB  |  265 lines

  1. package javax.swing.text;
  2.  
  3. import java.io.IOException;
  4. import java.io.ObjectInputStream;
  5. import java.io.ObjectOutputStream;
  6. import java.io.OutputStreamWriter;
  7. import java.io.PrintStream;
  8. import java.io.PrintWriter;
  9. import java.io.Serializable;
  10. import java.io.UnsupportedEncodingException;
  11. import java.util.Enumeration;
  12. import javax.swing.tree.TreeNode;
  13.  
  14. public abstract class AbstractDocument$AbstractElement implements Element, MutableAttributeSet, Serializable, TreeNode {
  15.    // $FF: synthetic field
  16.    private final AbstractDocument this$0;
  17.    private Element parent;
  18.    private transient AttributeSet attributes;
  19.  
  20.    public AbstractDocument$AbstractElement(AbstractDocument var1, Element var2, AttributeSet var3) {
  21.       this.this$0 = var1;
  22.       this.parent = var2;
  23.       this.attributes = var1.getAttributeContext().getEmptySet();
  24.       if (var3 != null) {
  25.          this.addAttributes(var3);
  26.       }
  27.  
  28.    }
  29.  
  30.    public void addAttribute(Object var1, Object var2) {
  31.       this.checkForIllegalCast();
  32.       AbstractDocument.AttributeContext var3 = this.this$0.getAttributeContext();
  33.       this.attributes = var3.addAttribute(this.attributes, var1, var2);
  34.    }
  35.  
  36.    public void addAttributes(AttributeSet var1) {
  37.       this.checkForIllegalCast();
  38.       AbstractDocument.AttributeContext var2 = this.this$0.getAttributeContext();
  39.       this.attributes = var2.addAttributes(this.attributes, var1);
  40.    }
  41.  
  42.    private final void checkForIllegalCast() {
  43.       Thread var1 = this.this$0.getCurrentWriter();
  44.       if (var1 == null || var1 != Thread.currentThread()) {
  45.          throw new StateInvariantError("Illegal cast to MutableAttributeSet");
  46.       }
  47.    }
  48.  
  49.    public abstract Enumeration children();
  50.  
  51.    public boolean containsAttribute(Object var1, Object var2) {
  52.       return this.attributes.containsAttribute(var1, var2);
  53.    }
  54.  
  55.    public boolean containsAttributes(AttributeSet var1) {
  56.       return this.attributes.containsAttributes(var1);
  57.    }
  58.  
  59.    public AttributeSet copyAttributes() {
  60.       return this.attributes.copyAttributes();
  61.    }
  62.  
  63.    public void dump(PrintStream var1, int var2) {
  64.       PrintWriter var3;
  65.       try {
  66.          var3 = new PrintWriter(new OutputStreamWriter(var1, "JavaEsc"), true);
  67.       } catch (UnsupportedEncodingException var8) {
  68.          var3 = new PrintWriter(var1, true);
  69.       }
  70.  
  71.       this.indent(var3, var2);
  72.       if (this.getName() == null) {
  73.          var3.print("<??");
  74.       } else {
  75.          var3.print("<" + this.getName());
  76.       }
  77.  
  78.       if (this.getAttributeCount() > 0) {
  79.          var3.println("");
  80.          Enumeration var4 = this.attributes.getAttributeNames();
  81.  
  82.          while(var4.hasMoreElements()) {
  83.             Object var5 = var4.nextElement();
  84.             this.indent(var3, var2 + 1);
  85.             var3.println(String.valueOf(var5) + "=" + this.getAttribute(var5));
  86.          }
  87.  
  88.          this.indent(var3, var2);
  89.       }
  90.  
  91.       var3.println(">");
  92.       if (this.isLeaf()) {
  93.          this.indent(var3, var2 + 1);
  94.          var3.print("[" + this.getStartOffset() + "," + this.getEndOffset() + "]");
  95.          AbstractDocument.Content var9 = this.this$0.getContent();
  96.  
  97.          try {
  98.             String var11 = var9.getString(this.getStartOffset(), this.getEndOffset() - this.getStartOffset());
  99.             if (var11.length() > 40) {
  100.                var11 = var11.substring(0, 40) + "...";
  101.             }
  102.  
  103.             var3.println("[" + var11 + "]");
  104.          } catch (BadLocationException var7) {
  105.          }
  106.       } else {
  107.          int var10 = this.getElementCount();
  108.  
  109.          for(int var12 = 0; var12 < var10; ++var12) {
  110.             AbstractDocument$AbstractElement var6 = (AbstractDocument$AbstractElement)this.getElement(var12);
  111.             var6.dump(var1, var2 + 1);
  112.          }
  113.       }
  114.  
  115.    }
  116.  
  117.    protected void finalize() throws Throwable {
  118.       AbstractDocument.AttributeContext var1 = this.this$0.getAttributeContext();
  119.       var1.reclaim(this.attributes);
  120.    }
  121.  
  122.    public abstract boolean getAllowsChildren();
  123.  
  124.    public Object getAttribute(Object var1) {
  125.       Object var2 = this.attributes.getAttribute(var1);
  126.       if (var2 == null) {
  127.          AttributeSet var3 = this.parent != null ? this.parent.getAttributes() : null;
  128.          if (var3 != null) {
  129.             var2 = var3.getAttribute(var1);
  130.          }
  131.       }
  132.  
  133.       return var2;
  134.    }
  135.  
  136.    public int getAttributeCount() {
  137.       return this.attributes.getAttributeCount();
  138.    }
  139.  
  140.    public Enumeration getAttributeNames() {
  141.       return this.attributes.getAttributeNames();
  142.    }
  143.  
  144.    public AttributeSet getAttributes() {
  145.       return this;
  146.    }
  147.  
  148.    public TreeNode getChildAt(int var1) {
  149.       return (TreeNode)this.getElement(var1);
  150.    }
  151.  
  152.    public int getChildCount() {
  153.       return this.getElementCount();
  154.    }
  155.  
  156.    public Document getDocument() {
  157.       return this.this$0;
  158.    }
  159.  
  160.    public abstract Element getElement(int var1);
  161.  
  162.    public abstract int getElementCount();
  163.  
  164.    public abstract int getElementIndex(int var1);
  165.  
  166.    public abstract int getEndOffset();
  167.  
  168.    public int getIndex(TreeNode var1) {
  169.       for(int var2 = this.getChildCount() - 1; var2 >= 0; --var2) {
  170.          if (this.getChildAt(var2) == var1) {
  171.             return var2;
  172.          }
  173.       }
  174.  
  175.       return -1;
  176.    }
  177.  
  178.    public String getName() {
  179.       return this.attributes.isDefined("$ename") ? (String)this.attributes.getAttribute("$ename") : null;
  180.    }
  181.  
  182.    public TreeNode getParent() {
  183.       return (TreeNode)this.getParentElement();
  184.    }
  185.  
  186.    public Element getParentElement() {
  187.       return this.parent;
  188.    }
  189.  
  190.    public AttributeSet getResolveParent() {
  191.       AttributeSet var1 = this.attributes.getResolveParent();
  192.       if (var1 == null && this.parent != null) {
  193.          var1 = this.parent.getAttributes();
  194.       }
  195.  
  196.       return var1;
  197.    }
  198.  
  199.    public abstract int getStartOffset();
  200.  
  201.    private final void indent(PrintWriter var1, int var2) {
  202.       for(int var3 = 0; var3 < var2; ++var3) {
  203.          var1.print("  ");
  204.       }
  205.  
  206.    }
  207.  
  208.    public boolean isDefined(Object var1) {
  209.       return this.attributes.isDefined(var1);
  210.    }
  211.  
  212.    public boolean isEqual(AttributeSet var1) {
  213.       return this.attributes.isEqual(var1);
  214.    }
  215.  
  216.    public abstract boolean isLeaf();
  217.  
  218.    private void readObject(ObjectInputStream var1) throws ClassNotFoundException, IOException {
  219.       var1.defaultReadObject();
  220.       SimpleAttributeSet var2 = new SimpleAttributeSet();
  221.       StyleContext.readAttributeSet(var1, var2);
  222.       AbstractDocument.AttributeContext var3 = this.this$0.getAttributeContext();
  223.       this.attributes = var3.addAttributes(SimpleAttributeSet.EMPTY, var2);
  224.    }
  225.  
  226.    public void removeAttribute(Object var1) {
  227.       this.checkForIllegalCast();
  228.       AbstractDocument.AttributeContext var2 = this.this$0.getAttributeContext();
  229.       this.attributes = var2.removeAttribute(this.attributes, var1);
  230.    }
  231.  
  232.    public void removeAttributes(Enumeration var1) {
  233.       this.checkForIllegalCast();
  234.       AbstractDocument.AttributeContext var2 = this.this$0.getAttributeContext();
  235.       this.attributes = var2.removeAttributes(this.attributes, var1);
  236.    }
  237.  
  238.    public void removeAttributes(AttributeSet var1) {
  239.       this.checkForIllegalCast();
  240.       AbstractDocument.AttributeContext var2 = this.this$0.getAttributeContext();
  241.       if (var1 == this) {
  242.          this.attributes = var2.getEmptySet();
  243.       } else {
  244.          this.attributes = var2.removeAttributes(this.attributes, var1);
  245.       }
  246.  
  247.    }
  248.  
  249.    public void setResolveParent(AttributeSet var1) {
  250.       this.checkForIllegalCast();
  251.       AbstractDocument.AttributeContext var2 = this.this$0.getAttributeContext();
  252.       if (var1 != null) {
  253.          this.attributes = var2.addAttribute(this.attributes, StyleConstants.ResolveAttribute, var1);
  254.       } else {
  255.          this.attributes = var2.removeAttribute(this.attributes, StyleConstants.ResolveAttribute);
  256.       }
  257.  
  258.    }
  259.  
  260.    private void writeObject(ObjectOutputStream var1) throws IOException {
  261.       var1.defaultWriteObject();
  262.       StyleContext.writeAttributeSet(var1, this.attributes);
  263.    }
  264. }
  265.